<?php
	## by ake 08/2012##
	
 class Manage_hotel extends CI_Controller{
 	
 	public function __construct(){
 		parent::__construct();
 		$this->load->library('session');
 		$this->load->library('form_validation');
 		$this->load->library('cismarty');
 		$this->load->model("apanel/template");
 		$this->load->model("apanel/db_hotel");
 		$this->load->library('pagination');
 	}
 	
 	public function index(){
 		redirect('manage_hotel/attraction_cat');
 	}
 	
 	public function attraction_cat($st=""){
 		if($this->session->userdata('sess_login') == null)
 			redirect('apanel');	
 		list($cat,$num,$page) = $this->db_hotel->attrac_listcat();
 		$this->cismarty->assign("Num_Rows",$num);
 		$this->cismarty->assign("cat",$cat);
 		$this->cismarty->assign("pagelink",$page);
 		if($st == "success"){
 			$this->cismarty->assign("status","<div class=\"mws-form-message success message\">Success</div>");
 		}
 		//== template
 		$this->cismarty->assign("header",$this->template->header());
 		$this->cismarty->assign("menu",$this->template->menu(2));
 		$this->cismarty->assign("footer",$this->template->footer());
 		$this->cismarty->assign("url",base_url());
 		$this->cismarty->display('apanel/attrac/attraction_cat.html');
 	}
 	
 	public function attraction_add(){
 		if($this->session->userdata('sess_login') == null)
 			redirect('apanel');
 		if($this->input->post('bntSubmit') != null){
 			$this->form_validation->set_rules("title_en","Category name","required");
 			$this->form_validation->set_rules("title_cn","Category name","trim");
 			$this->form_validation->set_rules("title_th","Category name","trim");
 			$this->form_validation->set_rules("desc_en","Description","required");
 			$this->form_validation->set_rules("desc_cn","Description","trim");
 			$this->form_validation->set_rules("desc_th","Description","trim");
 			if($this->form_validation->run() == FALSE){
 				$this->cismarty->assign("title_en",set_value('title_en'));
 				$this->cismarty->assign("title_cn",set_value('title_cn'));
 				$this->cismarty->assign("title_th",set_value('title_th'));
 				$this->cismarty->assign("desc_en",set_value('desc_en'));
 				$this->cismarty->assign("desc_cn",set_value('desc_cn'));
 				$this->cismarty->assign("desc_th",set_value('desc_th'));
 				
 				//set error 
 				$this->cismarty->assign("errortitle_en",form_error('title_en'));
 				$this->cismarty->assign("errordesc_en",form_error('desc_en'));
 			}else {
 				$data = array(
 							"name_en"=>trim($this->input->post('title_en')),
 							"name_zh_cn"=>trim($this->input->post('title_th')),
 							"name_th"=>trim($this->input->post('title_th')),
 							"description_en"=>trim($this->input->post('title_th')),
 							"description_zh_cn"=>trim($this->input->post('title_th')),
 							"description_th"=>trim($this->input->post('title_th')),
 							"created_by"=>$this->session->userdata("sess_username"),
 							"created_date"=>date("Y-m-d H:i:s")
 						);
 				$res = $this->db->insert('hotel_local_attraction_category',$data);	
 				if($res) redirect('manage_hotel/attraction_cat/success');
 				else  redirect('manage_hotel/attraction_cat/fail');
 			}
 			//$this->form_validation->set_rules("","","");
 		}
 		//== template
 		$this->cismarty->assign("header",$this->template->header());
 		$this->cismarty->assign("menu",$this->template->menu(2));
 		$this->cismarty->assign("footer",$this->template->footer());
 		$this->cismarty->assign("url",base_url());
 		$this->cismarty->assign("form_open",form_open_multipart());
 		$this->cismarty->assign("form_close",form_close());
 		$this->cismarty->display('apanel/attrac/attraction_add.html');
 	}
 	
 	
 	public function attraction_edit($id){
 		if($this->session->userdata('sess_login') == null)
 			redirect('apanel');
 		if($this->input->post('bntSubmit') != null){
 			$this->form_validation->set_rules("title_en","Category name","required");
 			$this->form_validation->set_rules("title_cn","Category name","trim");
 			$this->form_validation->set_rules("title_th","Category name","trim");
 			$this->form_validation->set_rules("desc_en","Description","required");
 			$this->form_validation->set_rules("desc_cn","Description","trim");
 			$this->form_validation->set_rules("desc_th","Description","trim");
 			if($this->form_validation->run() == FALSE){
 				$this->cismarty->assign("title_en",set_value('title_en'));
 				$this->cismarty->assign("title_cn",set_value('title_cn'));
 				$this->cismarty->assign("title_th",set_value('title_th'));
 				$this->cismarty->assign("desc_en",set_value('desc_en'));
 				$this->cismarty->assign("desc_cn",set_value('desc_cn'));
 				$this->cismarty->assign("desc_th",set_value('desc_th'));
 					
 				//set error
 				$this->cismarty->assign("errortitle_en",form_error('title_en'));
 				$this->cismarty->assign("errordesc_en",form_error('desc_en'));
 			}else {
 				$data = array(
 						"name_en"=>trim($this->input->post('title_en')),
 						"name_zh_cn"=>trim($this->input->post('title_th')),
 						"name_th"=>trim($this->input->post('title_th')),
 						"description_en"=>trim($this->input->post('title_th')),
 						"description_zh_cn"=>trim($this->input->post('title_th')),
 						"description_th"=>trim($this->input->post('title_th')),
 						"created_by"=>$this->session->userdata("sess_username"),
 						"created_date"=>date("Y-m-d H:i:s")
 				);
 				$this->db->where("pkid",$id);
 				$res = $this->db->update('hotel_local_attraction_category',$data);
 				if($res) redirect('manage_hotel/attraction_cat/success');
 				else  redirect('manage_hotel/attraction_cat/fail');
 			}
 			//$this->form_validation->set_rules("","","");
 		}else{
 			
 		}
 		//== template
 		$this->cismarty->assign("header",$this->template->header());
 		$this->cismarty->assign("menu",$this->template->menu(2));
 		$this->cismarty->assign("footer",$this->template->footer());
 		$this->cismarty->assign("url",base_url());
 		$this->cismarty->assign("form_open",form_open("manage_hotel/attraction_eidt/$id"));
 		$this->cismarty->assign("form_close",form_close());
 		$this->cismarty->display('apanel/attrac/attraction_edit.html');
 	}
 	
 	public function del($id){
 	
 	}
 	
 }